<?php
/**
 * Created by PhpStorm.
 * User: hisheng
 * Date: 2017/6/5
 * Time: 18:12
 */
namespace App\Http\Controllers\Api;
use App\Dao\SearchDao;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Input;

class SearchController extends Controller
{
    public $searchDao;
    public $parms = [
        'job'=>'学生',
        'amount'=>5000,
        'sort'=>'updated_at',
        'day'=>0
    ] ;
    
    public function __construct(SearchDao $searchDao)
    {
        $this->searchDao = $searchDao ;
        $this->initParms();
    }
    
    public function index(){
        $p = $this->parms;
        return $this->json($this->searchDao->search($p['job'],$p['amount'],$p['sort'],$p['day']));
    }
    
    public function initParms(){
        $this->setParm('job');
        $this->setParm('amount');
        $this->setParm('sort');
        $this->setParm('day');
    }
    
    public function setParm($name){
        $v = Input::get($name);
        if($v){
            if(isset($this->parms[$name])){
                $this->parms[$name] = $v;
            }
        }
    }
}